// Main text micro level results
// Low skill products by high skill workers
// Erica Owen
// Date 12/8/2022

version 14.2
use "mow_micro_rep.dta", clear


// DV 1: Relative income - Table 1

est drop _all


local z i.bach i.female age i.unemp  new_lngdppc lnnat lnpop i.year
local x1  c.reled
local x2 c.lnreal
local c if lforce==1 & imf_adv==0  

local y pctusdinc


mixed `y' `x1' `x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)  mle variance
est sto t1_1

mixed `y' `x1'##`x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)  mle variance
est sto t1_2

local x2 c.lnproj_mfg
mixed `y' `x1'##`x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)  mle variance
est sto t1_3



// DV 2: Support for trade & FDI - Table 2

local z  i.bach  i.female age i.unemp  new_lngdppc lnnat lnpop i.year  
local x1  c.reled
local x2 c.lnreal
local c if lforce==1 & imf_adv==0  

local y melogit support
 `y' `x1' `x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)   
est sto t2_1

 `y' `x1'##`x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)   
est sto t2_2

 `y' `x1'##`x2' CT1_eo `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)   
est sto t2_3

local x2 c.lnproj_mfg
local y melogit fdi_gr_bin
 `y' `x1' `x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)   
est sto t2_4

 `y' `x1'##`x2' `z'   `c' [pw=weight] || ccode: , vce(cluster ccode)     
est sto t2_5

  
 // Figure 3. Marginal effect income - log exports
est restore t1_2
capture drop me* lb* ub* at*


foreach i in 90 95 {
margins, dydx(reled) at(lnreal=(18(1)28)) level(`i')
	matrix out=r(table)'
	matrix dydx=out[1..11,1]
	matrix lb`i'=out[1..11,5]
	matrix ub`i'=out[1..11,6]
	svmat dydx, names(me`i')
	svmat lb`i', names(lb`i')
	svmat ub`i', names(ub`i')
	}
	
	matrix at=r(at)
	matrix at=at[1..11,2]
	svmat at, names(at)	

	foreach i in me lb ub {
		rename `i'901 `i'90
		rename `i'951 `i'95
		}
		
graph twoway  (rcap lb90 ub90 at1, msize(0) lwidth(thick)) (rcap lb95 ub95 at1) ///
	(hist lnreal, yaxis(2) freq fcolor(none) lcolor(gs12) ) ///
	(connected me95 at1, mcolor(red) yline(0) msymbol(O) lpattern(shortdash)), /// 
	legend(off) xtitle("Manufacturing exports (log)") graphregion(fcolor(white)) ///
	ylabel(none, axis(2)) ytitle("", axis(2)) ///
	ytitle("Marginal effect of relative education") ///
	note("95% confidence interval.") name(g1, replace) 
	



* Substantive effect
* one sd increase reled at high and low
margins, expression(_b[reled]*2.03+_b[c.reled#c.lnreal]*2.03*lnreal) at(lnreal=(18.75 27.79))
margins, dydx(bach)


// Figure 3b. Marginal effect income - log mfg projects

est restore t1_3
capture drop me* lb* ub* at*

foreach i in 90 95 {
margins, dydx(reled) at(lnproj_mfg=(0(1)8)) level(`i')

	matrix out=r(table)'
	matrix dydx=out[1..9,1]
	matrix lb`i'=out[1..9,5]
	matrix ub`i'=out[1..9,6]
	svmat dydx, names(me`i')
	svmat lb`i', names(lb`i')
	svmat ub`i', names(ub`i')
	}
	
	matrix at=r(at)
	matrix at=at[1..9,2]
	svmat at, names(at)	

	foreach i in me lb ub {
		rename `i'901 `i'90
		rename `i'951 `i'95
		}
		
graph twoway  (rcap lb90 ub90 at1, msize(0) lwidth(thick)) (rcap lb95 ub95 at1) ///
	(hist lnproj_mfg, yaxis(2) freq fcolor(none) lcolor(gs12) ) ///
	(connected me95 at1, mcolor(red) yline(0) msymbol(O) lpattern(shortdash)), /// 
	legend(off) xtitle("# Mfg. projects (log)") graphregion(fcolor(white)) ///
	ylabel(none, axis(2)) ytitle("", axis(2)) ///
	ytitle("Marginal effect of relative education") ///
	note("90 and 95% confidence intervals.") name(g2, replace) 
	
	
margins, expression(_b[reled]*2.03+_b[c.reled#c.lnproj_mfg]*2.03*lnproj_mfg) at(lnproj_mfg=(2.08 8.28))
margins, dydx(bach)
 
 
// Figure 4a. Marginal effect support - log exports
est restore t2_2
capture drop me* lb* ub* at*


foreach i in 90 95 {
margins, dydx(reled) at(lnreal=(18(1)28)) level(`i')
	matrix out=r(table)'
	matrix dydx=out[1..11,1]
	matrix lb`i'=out[1..11,5]
	matrix ub`i'=out[1..11,6]
	svmat dydx, names(me`i')
	svmat lb`i', names(lb`i')
	svmat ub`i', names(ub`i')
	}
	
	matrix at=r(at)
	matrix at=at[1..11,2]
	svmat at, names(at)	

	foreach i in me lb ub {
		rename `i'901 `i'90
		rename `i'951 `i'95
		}
		
graph twoway  (rcap lb90 ub90 at1, msize(0) lwidth(thick)) (rcap lb95 ub95 at1) ///
	(hist lnreal, yaxis(2) freq fcolor(none) lcolor(gs12) ) ///
	(connected me95 at1, mcolor(red) yline(0) msymbol(O) lpattern(shortdash)), /// 
	legend(off) xtitle("Manufacturing exports (log)") graphregion(fcolor(white)) ///
	ylabel(none, axis(2)) ytitle("", axis(2)) ///
	ytitle("Marginal effect of relative education") ///
	note("90 and 95% confidence interval.") name(g3, replace) 
	

margins, at(reled=(.5 3.9) lnreal=(19.85))  contrast(at effects)
margins, at(reled=(.5 3.9) lnreal=(26.34))  contrast(at effects)



// Figure 4b


est restore t2_5
capture drop me* lb* ub* at*

foreach i in 90 95 {
margins, dydx(reled) at(lnproj_mfg=(0(1)8)) level(`i')

	matrix out=r(table)'
	matrix dydx=out[1..9,1]
	matrix lb`i'=out[1..9,5]
	matrix ub`i'=out[1..9,6]
	svmat dydx, names(me`i')
	svmat lb`i', names(lb`i')
	svmat ub`i', names(ub`i')
	}
	
	matrix at=r(at)
	matrix at=at[1..9,2]
	svmat at, names(at)	

	foreach i in me lb ub {
		rename `i'901 `i'90
		rename `i'951 `i'95
		}
		
graph twoway  (rcap lb90 ub90 at1, msize(0) lwidth(thick)) (rcap lb95 ub95 at1) ///
	(hist lnproj_mfg, yaxis(2) freq fcolor(none) lcolor(gs12) ) ///
	(connected me95 at1, mcolor(red) yline(0) msymbol(O) lpattern(shortdash)), /// 
	legend(off) xtitle("# Mfg. projects (log)") graphregion(fcolor(white)) ///
	ylabel(none, axis(2)) ytitle("", axis(2)) ///
	ytitle("Marginal effect of relative education") ///
	note("90 and 95% confidence intervals.") name(g4, replace) 
	
	
	


// Substantive effects
margins, at(reled=(.5 3.9) lnproj_mfg=(2.70))  contrast(at effects)
margins, at(reled=(.5 3.9) lnproj_mfg=(8.07))  contrast(at effects)

